package com.ehome.poct.terminal.controller;


import com.ehome.core.page.PageInfo;
import com.ehome.poct.core.api.dto.order.PriceProfitSchemeDTO;
import com.ehome.poct.core.api.dto.report.PriceProfitDTO;
import com.ehome.poct.core.api.vo.order.DetectionVO;
import com.ehome.poct.core.api.vo.order.ProfitVO;
import com.ehome.poct.core.api.vo.order.TestStripPriceProfitSchemeOperateRecordVO;
import com.ehome.poct.core.api.dto.order.OperateRecordDTO;
import com.ehome.poct.terminal.api.dto.PriceProfitAbleDTO;
import com.ehome.poct.core.api.vo.PriceProfitVO;
import com.ehome.poct.core.api.vo.ProfitNameVO;
import com.ehome.poct.terminal.service.PriceProfitSchemeService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 价格方案管理
 *
 * @author muqiu
 * @since 2022/07/01 16:11
 **/
@Api(tags = "价格方案管理")
@ApiSupport(author = "muqiu")
@RequestMapping("/profit")
@RestController
@AllArgsConstructor
public class PriceProfitSchemeController {

    private final PriceProfitSchemeService priceProfitSchemeService;

    @ApiOperation("查询价格方案列表")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/list")
    public PageInfo<PriceProfitVO> list(PriceProfitSchemeDTO dto) {
        //是否活动方案不等于 1， 默认不显示活动方案
        dto.setIsActivity(1);
         return priceProfitSchemeService.list(dto);
    }

    @ApiOperation("保存价格方案")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping("/addProfit")
    public void addProfit(@RequestBody @Valid PriceProfitDTO dto) {
         priceProfitSchemeService.addProfit(dto);
    }

    @ApiOperation("获取所有检测项")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/getDetections")
    public List<DetectionVO> getDetections() {
        return priceProfitSchemeService.getDetections();
    }

    @ApiOperation("根据价格方案id查询价格方案详情")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/getById/{id}")
    public ProfitVO getById(@PathVariable(value = "id") Long id) {
        return priceProfitSchemeService.getById(id);
    }


    @ApiOperation("启用/禁用")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping("/updateStatus")
    public void updateStatus(@RequestBody PriceProfitAbleDTO priceProfitAbleDTO) {
         priceProfitSchemeService.updateStatus(priceProfitAbleDTO);
    }

    @ApiOperation("查询操作记录")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/getOperateRecord")
    public PageInfo<TestStripPriceProfitSchemeOperateRecordVO> getOperateRecord(OperateRecordDTO dto) {
        return priceProfitSchemeService.getOperateRecord(dto);
    }

    @ApiOperation("根据价格方案id或者价格方案查询价格方案详情")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/getByIdOrProfitName")
    public List<ProfitNameVO> getByIdOrProfitName(@RequestParam(value = "idOrProfitName",required = false) String idOrProfitName) {
        return priceProfitSchemeService.getByIdOrProfitName(idOrProfitName);
    }
}
